﻿using System;
using UnityEngine;

namespace Manox.Libs.MVC
{
    /// <summary>
    /// View base.
    /// </summary>
    [Serializable]
    public class ViewBase : MonoBehaviour
    {
        /// <summary>Data.</summary>        
        public Model Data { get; private set; }
        /// <summary>Vies manager.</summary>
        public ViewsManager ViewsManager { get; private set; }


        /// <summary>
        /// Set views manager.
        /// </summary>
        /// <param name="viewsManager"></param>
        public void SetViewsManager(ViewsManager viewsManager)
        {
            this.ViewsManager = viewsManager;
        }

        /// <summary>
        /// Set data.
        /// </summary>
        public virtual void SetData(Model data)
        {
            this.Data = data;

            this.OnDataSet();            
        }

        /// <summary>
        /// On data set.
        /// </summary>
        public virtual void OnDataSet() { }

        /// <summary>
        /// Awake.
        /// </summary>
        public virtual void Awake() { }

        /// <summary>
        /// On destroy.
        /// </summary>
        public virtual void OnDestroy() { }

        /// <summary>
        /// Start.
        /// </summary>
        public virtual void Start() { }

        /// <summary>
        /// Update.
        /// </summary>
        public virtual void Update() { }
    }

    /// <summary>
    /// View.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    public class View<T> : ViewBase where T : Model
    {
        /// <summary>Model.</summary>
        public T Model { get { return this.Data as T; } }
    }

    /// <summary>
    /// View.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    public class PositionRotationView<T> : View<T> where T : PositionRotationModel
    {
        /// <summary>
        /// Update.
        /// </summary>
        public override void Update()
        {
            if (this.Data != null)
            {
                this.transform.position = this.Model.Position.Get();
                this.transform.rotation = this.Model.Rotation.Get();
            }            
        }
    }

    /// <summary>
    /// Predicted position rotation view.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PredictedPositionRotationView<T> : PositionRotationView<T> where T : PositionRotationModel
    {

        /// <summary>
        /// Override update.
        /// </summary>
        public override void Update()
        {
            
        }
    }
}
